package com.pokermind.common.context;

/**
 * 请求上下文 - 用于在线程中传递RequestId等信息
 * 
 * @author PokerMind Team
 */
public class RequestContext {
    
    private static final ThreadLocal<String> REQUEST_ID = new ThreadLocal<>();
    private static final ThreadLocal<String> CONNECTION_ID = new ThreadLocal<>();
    private static final ThreadLocal<String> REQUEST_CONTENT = new ThreadLocal<>();  // V4.7: 存储完整请求内容
    
    /**
     * 设置当前请求ID
     */
    public static void setRequestId(String requestId) {
        REQUEST_ID.set(requestId);
    }
    
    /**
     * 获取当前请求ID
     */
    public static String getRequestId() {
        return REQUEST_ID.get();
    }
    
    /**
     * 设置当前连接ID
     */
    public static void setConnectionId(String connectionId) {
        CONNECTION_ID.set(connectionId);
    }
    
    /**
     * 获取当前连接ID
     */
    public static String getConnectionId() {
        return CONNECTION_ID.get();
    }
    
    /**
     * V4.7: 设置当前请求内容（完整JSON）
     */
    public static void setRequestContent(String requestContent) {
        REQUEST_CONTENT.set(requestContent);
    }
    
    /**
     * V4.7: 获取当前请求内容
     */
    public static String getRequestContent() {
        return REQUEST_CONTENT.get();
    }
    
    /**
     * 清理当前线程的上下文信息
     */
    public static void clear() {
        REQUEST_ID.remove();
        CONNECTION_ID.remove();
        REQUEST_CONTENT.remove();  // V4.7: 清理请求内容
    }
    
    // DEPRECATED: Removed getFormattedRequestInfo and getShortRequestId methods
    // to prevent ConnID truncation and ensure consistent logging format.
    // Use addRequestInfoToLog method in business logic classes instead.
}
